<template>
  <div>
    <div class="admin-top">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/ums/admin' }"
          >权限</el-breadcrumb-item
        >
        <el-breadcrumb-item :to="{ path: '/ums/admin' }"
          ><a href="#">角色列表</a></el-breadcrumb-item
        >
      </el-breadcrumb>
    </div>
    <div class="admin-suos">
      <div class="admin-suos-title">
        <div>
          <el-icon><Search /></el-icon>筛选搜索
        </div>
        <div>
          <el-button>重置</el-button>
          <el-button type="primary">查询搜索</el-button>
        </div>
      </div>
      <div class="admin-suos-input">
        <span> 账号/姓名：</span>
        <el-input
          class="w-50 m-2"
          size="large"
          placeholder="请输入账号、密码"
        />
      </div>
    </div>
    <div class="admin-add">添加</div>
    <div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="id" label="编号" width="180" />
        <el-table-column prop="name" label="角色名称" width="180" />
        <el-table-column prop="description" label="描述" />
        <el-table-column prop="adminCount" label="用户数" />
        <el-table-column label="添加时间">
          <template #default="scope">
            <div>
              {{ dayjs(scope.row.createTime).format("YYYY-MM-DD HH:mm:ss") }}
            </div>
          </template>
        </el-table-column>

        <el-table-column label="是否启用">
          <template #default="scope">
            <div>
              <el-switch
                v-model="scope.row.status"
                :active-value="1"
                :inactive-value="0"
              />
            </div>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template #default>
            <el-button link type="primary" size="small">编辑用户</el-button>
            <el-button link type="primary" size="small">分配角色</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-model:current-page="paginationParams.currentPage"
        v-model:page-size="paginationParams.pageSize"
        :page-sizes="[5, 10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="paginationParams.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import * as http from "@/request/http";
import { Ref, ref, reactive } from "vue";
import { dayjs } from "element-plus";
import { Search } from "@element-plus/icons-vue";
import { useTable } from "@/hooks/component/useTable";

// 封装
//vue2 mixins 复用多个组件公用的数据方法等逻辑
//vue3:封装一个useTable (获取表格数据、分页数据)
const { tableData, paginationParams, handleSizeChange, handleCurrentChange } =
  useTable(http.role.roleList, {});
</script>

<style lang="less" scoped>
:deep(.el-main) {
  --el-main-padding: 0px;
}
.admin-top {
  height: 30px;
  border-bottom: 1px solid #cbcbcb;
}
.admin-suos {
  margin: 20px auto;
  width: 100%;
  height: 140px;
  box-shadow: 0px 0px 8px rgb(232, 232, 232);
  .admin-suos-title {
    display: flex;
    justify-content: space-between;
    padding: 20px;
  }
  .admin-suos-input {
    padding: 0px 70px;
    display: flex;
    flex-direction: row;
    align-items: center;
    :deep(.el-input) {
      width: 300px;
    }
    :deep(.el-input__inner) {
      width: 300px;
    }
  }
}
</style>
